/**
 * 
 */
package stc.skymobi.business;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import stc.skymobi.util.Transformer;


/**
 * @author hp
 *
 */
public abstract class AbstractTransactionService implements TransactionService {

    private static final Logger logger = LoggerFactory.getLogger(AbstractTransactionService.class);
    
	protected Transformer<Object, Object>	bean2content;
	protected List<String>					statusIgnoredProperties = new ArrayList<String>();
	
	public Transformer<Object, Object> getBean2content() {
		return bean2content;
	}

	public void setBean2content(Transformer<Object, Object> bean2content) {
		this.bean2content = bean2content;
	}

	protected Object findContent(Object bean) {
		return	bean2content.transform(bean);
	}
	
	protected void removeAllIgnoredProperties(Object bean) {
		for ( String property : this.statusIgnoredProperties ) {
			try {
				PropertyUtils.setProperty(bean, property, null);
			} catch (Exception e) {
				logger.error("removeAllIgnoredProperties", e);
			}
		}
	}
	
	/* (non-Javadoc)
	 * @see com.skymobi.util.Transformer#transform(java.lang.Object)
	 */
	public abstract Object transform(Object requestBean);
	
	/* (non-Javadoc)
	 * @see com.skymobi.business.TransactionService#getTransactionStatus()
	 */
	public abstract Object getTransactionStatus();

	public List<String> getStatusIgnoredProperties() {
		return Collections.unmodifiableList( statusIgnoredProperties);
	}

	public void setStatusIgnoredProperties(List<String> statusIgnoredProperties) {
		this.statusIgnoredProperties.clear();
		this.statusIgnoredProperties.addAll(statusIgnoredProperties);
	}


}
